<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateProjectConditions extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('project_conditions', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->string('type_key')->unsigned()->nullable();
            $table->foreign('type_key')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->text('own_version')->nullable();

            $table->integer('min')->nullable();
            $table->integer('target')->nullable();
            $table->integer('percent')->nullable();

            $table->integer('loan')->nullable();
            $table->integer('period')->nullable();

            $table->string('rating_key')->unsigned();
            $table->foreign('rating_key')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->string('repayment_key')->unsigned();
            $table->foreign('repayment_key')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->integer('deffer_period')->nullable()->comment('Срок отсрочки');

            $table->integer('penalty_per_day')->nullable()->comment('Размер пени в день');
            $table->boolean('charge_penalty_first_day')->default(true)->comment('Начало начисления пени');

            $table->integer('percents_calculation')->nullable()->comment('Расчет % за пользование займом при просрочке');

            $table->string('output_key')->unsigned();
            $table->foreign('output_key')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('project_conditions');
    }
}
